﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Web.Utility;
using BySoft.Server.Common;
using BySoft.Server.Consts;
using BySoft.Server.Common.Entity;
using BySoft.Server.Business;
using BySoft.Server.Common.Enum;
using OneSoft.EntityCore;
using System.Web.UI.HtmlControls;
using ZCZP.Web.Site;
using System.Web;

namespace BySoft.Web.Site.OutSource
{
    public partial class KnifeInStockView : AuthBasePage
    {
        #region 属性定义
        private string m_strsequenceName = "BsKnifeinstock" + DateTime.Now.ToString("yyyyMMdd");
        private string m_strTbl = "BS_KnifeInStock";
        private string m_strMainKey = "BillID";

        private DataTable DtKnifeInStockData
        {
            get
            {
                if (null == Session["KnifeInStockData"])
                {
                    return CreateDT();
                }
                else
                {
                    return (DataTable)Session["KnifeInStockData"];
                }
            }
            set
            {
                Session["KnifeInStockData"] = value;
            }
        }

        private DataTable CreateDT()
        {
           
            return  BsKnifeinstock.CreateDetailDT();
        }
        #endregion

        #region 初始化及绑定控件
        private void InitData()
        {
            DtKnifeInStockData = null;
            
            SetControlAttr(new BsKnifeinstockEntity(), tBase);
            string strCode = HttpUtility.UrlDecode(UIHelper.GetQueryStringValue("id").Trim());
            InitHead(strCode);
            InitBody(strCode);
        }
        private void InitHead(string strCode)
        {
            DataTable dt = BsKnifeinstock.SelectHeadData(strCode);
            DBtoControlHead(this.Page, dt, tBase, @"../Knife/KnifeInStockList.aspx");
            DataRow row = dt.Rows[0];
             hdCode.Value = CommonMethod.GetString(row["BillID"]);
             hidSupplierID.Value = CommonMethod.GetString(row["SupplierID"]);
             txtSupplierName.Text = CommonMethod.GetString(row["SupplierName"]);
        }

        private void InitBody(string strCode)
        {
            DataTable dt = BsKnifeinstock.SelectDetailData(strCode);
           
            DtKnifeInStockData = dt.Copy();
            BindData();
        }


        #endregion

        #region 控件事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdResult.Style.Add("word-break", "keep-all");
                grdResult.Style.Add("word-wrap", "normal");
                InitData();
            }
            Master.ValidationGroup = "gSubmit";
            UIHelper.RunScript(this.UpdatePanel1, "Refreashtab();");
        }

       

     

        private void BindData()
        {
            DataView dv = new DataView(DtKnifeInStockData);
            dv.RowFilter = " IsDel <> '1' ";
            DataTable dt = dv.ToTable();
            if (dt != null && dt.Rows.Count > 0)
            {
                int index = 1;
                foreach (DataRow dr in dt.Rows)
                {
                    dr["DetailID"] = index;
                   // dr["WorkOrderNo"] = txtOrderID.Text.Trim() + index.ToString();
                    index++;
                }
                grdResult.DataSource = dt;
                grdResult.DataBind();
            }
            else
            {
                UIHelper.BindEmptyGridView(grdResult, dt);
            }

            UIHelper.RunScript(this.UpdatePanel2, "Refreashtab();");
        }


      
       


        #endregion

        #region 本地方法
       
        #endregion


    }
}

